package com.sean.example.reflection;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class MyReflection {
	
	public static void main(String[] args) {
		try {
			People people = new People();
			Class cla = people.getClass();
			
			Method[] methods = cla.getMethods();
			for(Method method : methods) {
				System.out.println(method.getName());
			}
			
			Field[] fields = cla.getFields();
			for(Field field : fields) {
				System.out.println(field.getName());
			}
			
			Field field = cla.getField("n");
			Integer i = (Integer)field.get(people);
			System.out.println(i.intValue());
			
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

}
